#! /usr/bin/env bash

# 将本地仓库的代码复制一份（防止编译弄来原来仓库的代码）

# 远程仓库地址
REMOTE_REPO=$1
# 本地仓库地址
LOCAL_REPO=$2
# 复制仓库的目标地址
BUILD_DEST=$3

if [[ -z ${REMOTE_REPO} || -z ${LOCAL_REPO} || -z ${BUILD_DEST} ]]; then
    echo "invalid call pull-repo.sh '$REMOTE_REPO' '$LOCAL_REPO' '$BUILD_DEST'"
elif [[ ! -d ${BUILD_DEST} ]]; then
    git clone --reference ${LOCAL_REPO} ${REMOTE_REPO} ${BUILD_DEST}
    cd ${BUILD_DEST}
    git repack -a
else
    cd ${BUILD_DEST}
    git fetch --all --tags
    cd -
fi